/*
 * @(#)SystemParameterFactory.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.workflow.applet.net;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.StringTokenizer;

/**
  SystemParameterFactory.java

  This class is for getting system parameters;

    @author          Rollo Chan
    @company         DCIVision Limited
    @creation date   26/06/2003
    @version         $Revision: 1.1 $
*/

public class SystemParameterFactory {

  public static final String REVISION = "$Revision: 1.1 $";

  private static Hashtable hashSysParam;

  private SystemParameterFactory() {
  }

  /**
   * init
   *
   * @param hashIn  Hashtable contains all system parameters
   */
  public static void init(Hashtable hashIn) {
    hashSysParam = hashIn;
  }

  /**
   * getSystemParameter
   *
   * @param key   The parameter code.
   * @return      The parameter value.
   */
  public static String getSystemParameter(String key) {
    return((String)hashSysParam.get(key));
  }

  /**
   * getSystemParameterBoolean
   *
   * @param key   The parameter code.
   * @return      The parameter value in boolean.
   */
  public static boolean getSystemParameterBoolean(String key) {
    return(new Boolean((String)hashSysParam.get(key)).booleanValue());
  }

  /**
   * getSystemParameterInteger
   *
   * @param key   The parameter code.
   * @return      The parameter value in integer.
   */
  public static Integer getSystemParameterInteger(String key) {
    return(new Integer((String)hashSysParam.get(key)));
  }

  /**
   * getSystemParameterDouble
   *
   * @param key   The parameter code.
   * @return      The parameter value in double.
   */
  public static Double getSystemParameterDouble(String key) {
    return(new Double((String)hashSysParam.get(key)));
  }
  
  /**
   * getSystemParameterDouble
   *
   * @param key   The parameter code.
   * @return      The parameter value in HashMap.
   */
  public static List getSystemParameterList(String key) {
    List result = new ArrayList();
    String valueStr = (String) hashSysParam.get(key);
    StringTokenizer tokenizer = new StringTokenizer(valueStr, ",");
    while (tokenizer.hasMoreTokens()){
      String tokenVal = tokenizer.nextToken();
      result.add(tokenVal);
    }
    return result;
  }

  /**
   * setSystemParameter
   *
   * @param key   The parameter key.
   * @param value The parameter value.
   */
  public static void setSystemParameter(String key, String value) {
    if (key != null && value != null) {
      hashSysParam.put(key, value);
    }
  }
}